package com.flejay.dreamrecruiter.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import com.flejay.dreamrecruiter.dao.ICVReaderDao;
import com.flejay.dreamrecruiter.dao.IConfigurationLoaderDao;
import com.flejay.dreamrecruiter.model.CurriculumVitae;
import com.flejay.dreamrecruiter.model.SubTag;
import com.flejay.dreamrecruiter.model.Tag;
import com.flejay.dreamrecruiter.tools.ExceptionHandlerTool;

/**
 * Service d'extraction
 * 
 * @author Victor Fleurant
 *
 */
@Singleton
@Named("extractorFileService")
public class ExtractorFileService implements IExtractorService {

	@Inject
	@Named("fileConfigurationLoaderDao")
	private IConfigurationLoaderDao configurationLoaderDao;
	
	@Inject
	@Named("textCVReaderDao")
	private ICVReaderDao cvReaderDao;
	
	@Override
	public List<CurriculumVitae> loadCVs(final String path) {
		ExceptionHandlerTool.controlString(path, "path");
		return cvReaderDao.loadCVs(path);
	}

	@Override
	public List<Tag> loadConfiguration(final String mode, final String language) {
		ExceptionHandlerTool.controlString(mode, "mode");
		ExceptionHandlerTool.controlString(language, "language");
		List<Tag> tags =  configurationLoaderDao.loadTagConfiguration(mode, language);
		Map<String,List<SubTag>> subTagsOrderedByTagLabel = configurationLoaderDao.loadSubTagsConfiguration(language + "_" + mode);
		for(Tag tag : tags){
			List<SubTag> subTags = subTagsOrderedByTagLabel.get(tag.getLabel());
			if (subTags == null){
				subTags = new ArrayList<SubTag>();
			}
			tag.setSubTags(subTags);
		}
		return tags;
	}

	
}
